package com.feng.gaoerfu.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.feng.gaoerfu.R;
import com.feng.gaoerfu.bean.ContactPerson;

import java.util.List;

/**
 * @time 2017/9/13 0013 22:37
 */

public class ContactAdapter extends BaseQuickAdapter<ContactPerson> {
    private final List<ContactPerson> mList;

    public ContactAdapter(int layoutResId, List<ContactPerson> data) {
        super(layoutResId, data);
        this.mList = data;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, ContactPerson data) {
        baseViewHolder.setText(R.id.contact_tv_name, data.name)
                .setText(R.id.contact_tv_phone, data.PhoneNumber);
    }

    // 根据分类的首字母的Char ascii值获取其第一次出现该首字母的位置
    public int getPositionForSection(int section) {
        for (int i = 0; i < mList.size(); i++) {
            char firstChar = mList.get(i).getFirstChar();
            if (firstChar == section) {
                return i;
            }
        }
        return -1;
    }
}
